<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 面向对象编程思想（OOP） Oriented Object Programming
        // 封装 继承 多态
        // 基类 （父类）
        function Person(name, age) {
            this.name = name;
            this.age = age
        }

        Person.prototype.run = function() {
            console.log("我是短跑冠军")
        }

        // 子类
        function Boy(name, age) {
            // 1.构造函数继承
            Person.call(this, name, age)
            this.loves = function() {
                console.log("睡觉觉 玩玩具")
            }
        }

        // 2.原型继承
        // Boy.prototype = new Person()

        // var b1 = new Boy("xiaogang", 18)
        // console.log(b1.name)
        // console.log(b1.run);

        // 4.寄生组合继承
        function inherit(Father,Son) {
            var newProto = Object.assign({}, Father.prototype, Son.prototype)
            Son.prototype = newProto;
            newProto.constructor = Son
        }

        inherit(Person, Boy);
        var b1 = new Boy("xiaowang", 15)
        console.log(b1.run)


    </script>
</body>
</html>